package com.wc.算法提高课.F第六章_基础算法.递推与递归.分形之城;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/10/1 13:26
 * @description https://www.acwing.com/problem/content/description/100/
 */
public class Main {
    /**
     * 原始图像
     * 0 1
     * 3 2
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static long n, a, b;

    public static void main(String[] args) {
        int T = sc.nextInt();
        while (T-- > 0) {
            n = sc.nextLong();
            a = sc.nextLong();
            b = sc.nextLong();
            long[] A = get(n, a - 1), B = get(n, b - 1);
            double dx = A[0] - B[0], dy = A[1] - B[1];
            out.printf("%.0f\n’", 10 * Math.sqrt(dx * dx + dy * dy));
        }
        out.flush();
    }

    static long[] get(long n, long a) {
        if (n == 0) return new long[]{0, 0};
        long block = 1L << 2 * n - 2, len = 1L << n - 1;
        // 去找子区域的位置
        long[] A = get(n - 1, a % block);
        long x = A[0], y = A[1];
        // 看a在那一块区域
        long z = a / block;
        if (z == 0) return new long[]{y, x};
        if (z == 1) return new long[]{x, y + len};
        if (z == 2) return new long[]{x + len, y + len};
        return new long[]{len + len - 1 - y, len - 1 - x};
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
